import { ApiProperty } from '@nestjs/swagger';
import { Posts } from '../../posts/entities/post.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('tags')
export class Tags {
  @PrimaryGeneratedColumn()
  id: number;

  // 标签名
  @ApiProperty({ description: '标签名' })
  @Column({ unique: true, length: 50, comment: '标签名', default: null })
  name: string;

  @ApiProperty({ description: '文章' })
  @ManyToMany(() => Posts, (post) => post.tags)
  posts: Array<Posts>;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
  })
  createTime: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
  })
  updateTime: Date;
}
